package cn.westv.scps.service.sys.user.impl;

import cn.westv.scps.dao.BaseDao;
import cn.westv.scps.domain.SysUserEntity;
import cn.westv.scps.service.sys.user.ISysUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/08/10.
 */
@Service
@Transactional
public class SysUserServiceImpl implements ISysUserService{
    @Resource
    private BaseDao baseDao;
    @Override
    public SysUserEntity userLogin(String account, String password) {
        String hql = " from SysUserEntity where account = ? and password=? and status <> ?";
        List<Object> params = new ArrayList<Object>();
        params.add(account);
        params.add(password);
        params.add(SysUserEntity.STATUS_DELETE);
        List<SysUserEntity> list = baseDao.find(hql,SysUserEntity.class,params.toArray());
        if(list != null && list.size() > 0){
            return  list.get(0);
        }
        return null;
    }


    @Transactional(readOnly=false,isolation= Isolation.DEFAULT,propagation= Propagation.REQUIRED)
    @Override
    public void update(SysUserEntity user)  {
        baseDao.update(user);
    }
}
